﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ScheduleMaker.DB.CoreDAO;
using ScheduleMaker.DB;
using ScheduleMaker.DB.Domain;
using ScheduleMaker.ConfigManager;

namespace ScheduleMaker
{
    public partial class SmAdmSubjectAddUniForm : Form
    {
        smAdminForm parentForm;

        public SmAdmSubjectAddUniForm(smAdminForm _parentForm)
        {
            InitializeComponent();
            this.parentForm = _parentForm;
            label4.Visible = false;
            nudSubCount.Visible = false;
            btnSubAdd.Enabled = false;
        }

        private void cbSubAdd_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbSubAdd.Text == "ćwiczenia")
            {
                label4.Visible = true;
                nudSubCount.Visible = true;
            }
            else
            {
                label4.Visible = false;
                nudSubCount.Visible = false;
            }
            btnSubAdd.Enabled = true;
        }

        private void btnSubAdd_Click(object sender, EventArgs e)
        {

            //// dodawanie nowego przedmiotu
            // Dodawanie nowej sali
            SubjectDAO subjectDAO = DAOFactory.getSubjectDAO(ConfigManager.ConfigManager.getConfiguration().Type);


            if (ConfigManager.ConfigManager.getConfiguration().Type == Mode.University)
            {
                DB.Domain.Core.Subject subject = new SubjectUniversity();
                subject.Name = tbSubjectName.Text;
                
                // czy wykład
                if (cbSubAdd.Text == "ćwiczenia")
                {
                    subject.Lecture = false;
                    subject.Time = (int)nudSubTime.Value;
                    subject.Count = (int)nudSubCount.Value;
                }
                else
                {
                    subject.Time = (int)nudSubTime.Value;
                    subject.Lecture = true;
                    subject.Count = 1;
                }
                
                subjectDAO.save(subject);
            }

            MessageBox.Show("Przedmiot zsotał dodany", "Dodanie przedmiotu", MessageBoxButtons.OK, MessageBoxIcon.Information);



            this.parentForm.getSubjectList();
            this.Dispose();
        }

        private void SmAdmSubjectAddUniForm_Load(object sender, EventArgs e)
        {

        }
    }
}
